<?php

namespace App\Datas;

use App\Tools\FunTool;

class EventList extends ClickHouse
{
    private static $instance = null;

    public $tableName = "event_list";

    private function __construct(){
    }

    public static function getInstance() {
        if (empty(self::$instance) && !(self::$instance instanceof EventList)) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    public function addData($data) {
        $this->getClient()->insert($this->tableName,[$data],array_keys($data));
    }

    private function getBaseData () {
        return [
            "created_time" => FunTool::getReduceTime(4),
            "platform" => FunTool::getPlatform() == 1 ? "ios" : "android",
            "ver_name" => FunTool::getVersion(),
            "device_id" => FunTool::getDeviceId(),
        ];
    }

    public function subscribePayEvent($platform,$ver_name,$device_id,$result) {

        $data = [
            "created_time" => FunTool::getReduceTime(4),
            "platform" => $platform == 1 ? "ios" : "android",
            "ver_name" => $ver_name,
            "device_id" => $device_id,
            "name" => 'Subscribe_results',
            "type" => "Received",
            "results" => $result
        ];

        $this->addData($data);
    }

    public function select($sql){
       return $this->getClient()->select($sql);
    }


}